# online_answer_records/models.py
from sqlalchemy import Column, String, Integer, Boolean, Text, DateTime
from sqlalchemy.sql import func
from ..database import Base


class OnlineAnswerRecord(Base):
    __tablename__ = "online_answer_records"

    id = Column(Integer, primary_key=True, autoincrement=True, comment="主键：自增编号")
    user_id = Column(Integer, nullable=False, comment="用户ID（关联用户表）")
    question_id = Column(Integer, nullable=False, comment="题目ID（关联题目表）")
    content = Column(Text, nullable=False, comment="题目内容")
    answer = Column(Text, nullable=False, comment="题目答案")
    user_answer = Column(Text, nullable=False, comment="用户回答的答案")
    is_correct = Column(Boolean, nullable=False, comment="是否答对：true/ false")
    time_taken = Column(Integer, nullable=False, comment="答题用时（单位：秒）")
    answered_at = Column(DateTime, nullable=False, default=func.now(), comment="回答时间")
    session_id = Column(String(100), nullable=True, comment="答题会话ID（用于区分不同答题会话）")